﻿using MVCProject.DAL;
using MVCProject.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVCProject.BLL
{
    public abstract class BaseBll<T> where T : class
    {
        public BaseDal<T> Dal { get; set; }
        public BaseBll()
        {
            //在构造函数里调用
            SetDal();
        }
        /// <summary>
        /// 给数据层创建对象
        /// </summary>
        public abstract void SetDal();



        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Add(T t)
        {
            Dal.Add(t);
            return Dal.SaveChanges();

        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool Add(List<T> list)
        {
            Dal.Add(list);
            return Dal.SaveChanges();

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Delete(T t)
        {
            Dal.Delete(t);
            return Dal.SaveChanges();

        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool Delete(List<T> list)
        {
            Dal.Delete(list);
            return Dal.SaveChanges();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Update(T t)
        {
            Dal.Update(t);
            return Dal.SaveChanges();

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public IQueryable<T> Query()
        {
            return Dal.Query();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        public List<T> QueryList()
        {
            return Dal.Query().ToList();
        }

    }
}
